(function () {
    return {
        initControl: function (oControl) {
            var v = oControl.value;
            v.title = "提交";
            v.colorstyle = "";
            v.sizestyle = "";
            v.outlined = false;
            v.inverted = false;
            v.rounded = false;
            v.loading = false;
            v.iswaver = false;
        },
        compile: function (compileContext, doc, entity) {

            var cc = compileContext;
            var tc = cc.templateCoder;

            var cls = [];
            cls.push("button");


            if (entity.value.colorstyle) cls.push(entity.value.colorstyle);
            if (entity.value.sizestyle) cls.push(entity.value.sizestyle);

            if (entity.value.outlined) cls.push("is-outlined");
            if (entity.value.inverted) cls.push("is-inverted");
            if (entity.value.rounded) cls.push("is-rounded");
            if (entity.value.loading) cls.push("is-loading");
            if ("iswaver" in entity.value && entity.value.iswaver) cls.push("ripple-effect");

            tc.add("<button");
            tc.add(" class=\"" + cls.join(" ") + "\"");
            tc.add(" :click=\"onClick" + entity.id + "\"");
            tc.add(" disabled=\"${job && $.toInt(job.isdeal)}\"");
            tc.add(">");
            tc.add(entity.value.title);
            tc.add("</button>");

            var names = {};
            var nameArr = [];
            $.each(cc.dataNames, function (n) {
                names[n] = 0
            });

            var ec = cc.eventCoder;
            var clickCode = "";
            clickCode += "onClick" + entity.id + ":function(e){var me=this;" +
                "var cond={appid:me.appid,jobid:me.jobid};";
            $.each(names, function (v,n) {
                clickCode += "cond['" + n + "']=me." + n + ".value;";
            });
            clickCode +=
                "$.api(\"workflow.App.Submit\",cond)" +
                ".then(function(value){" +
                "$.alertBox('提示','提交成功',function(){$.back();})" +
                "},function(err){$.errorBox(\"错误\",err.message);})" +
                "}";
            ec.add(clickCode);
        }
    }
})();